package com.spyx.product.controller;


import com.spyx.product.service.FileUploadService;
import com.spyx.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Api(tags = "文件上传接口")
@RestController
@RequestMapping("admin/product")
//@CrossOrigin
public class FileUploadController {

    @Autowired
    private FileUploadService fileUploadService;

    //文件上传,当发送上传请求时，会发送文件对象到后台服务器
    //服务器端使用MultipartFile 接收文件
    @PostMapping("fileUpload")
    @ApiOperation("文件上传oss")
    public Result fileUpload(MultipartFile file) throws Exception{
        System.out.println("文件上传-----");
        String path = fileUploadService.uploadimage(file);

        return Result.ok(path);
    }
}
